package com.example.bookmanage.controller;

import com.example.bookmanage.domain.TableDataInfo;
import com.example.bookmanage.domain.borrow.vo.BorrowVO;
import com.example.bookmanage.domain.reader.dto.ReaderDTO;
import com.example.bookmanage.domain.reader.dto.ReaderEditDTO;
import com.example.bookmanage.domain.reader.dto.ReaderQueDTO;
import com.example.bookmanage.domain.reader.dto.ReaderUpStatusDTO;
import com.example.bookmanage.result.Result;
import com.example.bookmanage.service.ReaderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "读者管理")
@RestController
@RequestMapping("/reader")
public class ReaderController extends BaseController {

    @Autowired
    private ReaderService readerService;

    /**
     * 读者列表
     *
     * @param readerQueDTO
     * @return
     */
    @Operation(summary = "读者列表")
    @GetMapping("/list")
    public TableDataInfo list(@ParameterObject ReaderQueDTO readerQueDTO) {
        return getTableDataInfo(readerService.list(readerQueDTO));
    }

    /**
     * 添加读者
     *
     * @param readerDTO
     * @return
     */
    @Operation(summary = "添加读者")
    @PostMapping("/add")
    public Result<?> add(@RequestBody ReaderDTO readerDTO) {
        return toResult(readerService.save(readerDTO));
    }

    /**
     * 修改读者信息
     *
     * @param readerEditDTD
     * @return
     */
    @Operation(summary = "修改读者信息")
    @PutMapping("/update")
    public Result<?> update(@RequestBody ReaderEditDTO readerEditDTD) {
        return toResult(readerService.update(readerEditDTD));
    }

    /**
     * 修改读者状态
     *
     * @param readerUpStatusDTO
     * @return
     */
    @Operation(summary = "修改读者状态")
    @PutMapping("/updateStatus")
    public Result<?> updateStatus(@RequestBody ReaderUpStatusDTO readerUpStatusDTO) {
        return toResult(readerService.updateStatus(readerUpStatusDTO));
    }

    /**
     * 查询读者借阅记录
     *
     * @param readerId
     * @return
     */
    @Operation(summary = "查询读者借阅记录")
    @GetMapping("/borrowRecords/{readerId}")
    public Result<List<BorrowVO>> getBorrowRecords(@PathVariable Long readerId) {
        return Result.success(readerService.getBorrowRecords(readerId));
    }
}
